home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE02 / RPC10C / RPC10C.ZIP / RPRINTER.INT < prev    next >
Encoding:
Text File  |  1995-04-27  |  9.6 KB  |  290 lines

  1. unit RPrinter;
  2.  
  3. interface
  4.  
  5. uses
  6.   ExtCtrls,
  7.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  8.   Forms, Dialogs, StdCtrls, Printers;
  9.  
  10. { Status format characters }
  11. { %% - % character }
  12. { %p - Current Page }
  13. { %f - First Page }
  14. { %l - Last Page }
  15. { %d - Printer Device Name }
  16. { %r - Printer Driver Name }
  17. { %t - Printer Port }
  18. { %0 through %9 - Status Text Line }
  19.  
  20. const
  21.   NA = -32768; { n/a value }
  22.   BOXLINEALL = 15;
  23.   BOXLINEBOTTOM = 8;
  24.   BOXLINEHORIZ = 12;
  25.   BOXLINELEFT = 1;
  26.   BOXLINENONE = 0;
  27.   BOXLINERIGHT = 2;
  28.   BOXLINETOP = 4;
  29.   BOXLINEVERT = 3;
  30.  
  31. type
  32.   EReportPrinter = class(Exception);
  33.  
  34.   TPrintPageEvent = function(    Sender: TObject;
  35.                              var PageNum: integer): boolean of object;
  36.  
  37.   TPrintJustify = (pjCenter,pjLeft,pjRight);
  38.   TPrintUnits = (unInch,unMM,unUser);
  39.   TLineHeightMethod = (lhmLinesPerInch,lhmFont);
  40.   TBKMode = (bkTransparent,bkOpaque);
  41.   TDestination = (destPrinter,destPreview,destFile);
  42.  
  43.   TReportPrinter = class(TComponent)
  44.   protected
  45.   { Property read/write methods }
  46.     function GetCanvas: TCanvas;
  47.     procedure SetStatusText(Value: TStrings);
  48.     procedure SetLinesPerInch(NewLinesPerInch: integer);
  49.     procedure SetLine(NewLine: integer);
  50.     procedure SetColumn(NewColumn: integer);
  51.     procedure SetLeftMargin(LeftWidth: double);
  52.     function GetLeftMargin: double;
  53.     procedure SetRightMargin(RightWidth: double);
  54.     function GetRightMargin: double;
  55.     procedure SetTopMargin(TopWidth: double);
  56.     function GetTopMargin: double;
  57.     procedure SetBottomMargin(BottomWidth: double);
  58.     function GetBottomMargin: double;
  59.     procedure SetTabShade(Shade: integer);
  60.     function GetLeftWaste: double;
  61.     function GetRightWaste: double;
  62.     function GetTopWaste: double;
  63.     function GetBottomWaste: double;
  64.     function GetXPos: double;
  65.     procedure SetXPos(NewXPos: double);
  66.     function GetYPos: double;
  67.     procedure SetYPos(NewYPos: double);
  68.     procedure SetUnits(Units: TPrintUnits);
  69.     procedure SetUnitsFactor(UnitsFactor: double);
  70.     function GetPageHeight: double;
  71.     function GetPageWidth: double;
  72.     procedure SetBold(State: boolean);
  73.     function GetBold: boolean;
  74.     procedure SetUnderline(State: boolean);
  75.     function GetUnderline: boolean;
  76.     procedure SetItalic(State: boolean);
  77.     function GetItalic: boolean;
  78.     procedure SetStrikeout(State: boolean);
  79.     function GetStrikeout: boolean;
  80.     procedure SetOrientation(Value: TPrinterOrientation);
  81.     procedure SetCopies(Value: integer);
  82.     function GetCopies: integer;
  83.     procedure SetPrinterIndex(Value: integer);
  84.     function GetPrinterIndex: integer;
  85.     function GetDeviceName: string;
  86.     function GetDriverName: string;
  87.     function GetPort: string;
  88.     procedure SetDestination(Value: TDestination);
  89.     procedure SetBKColor(Value: TColor);
  90.     function GetBKColor: TColor;
  91.  
  92.   public
  93.   { Public methods }
  94.     constructor Create(AOwner: TComponent); override;
  95.     destructor Destroy;
  96.     procedure CheckPrinting;
  97.     procedure CheckNotPrinting;
  98.  
  99.     procedure Execute;
  100.     procedure NewPage;
  101.     procedure Abort;
  102.     procedure AbortPage;
  103.     procedure UpdateStatus;
  104.     procedure Reset;
  105.     procedure ResetPrinter;
  106.  
  107.   { Positioning Methods }
  108.     function X2D(Pos: double): integer;
  109.     function Y2D(Pos: double): integer;
  110.     procedure CR;
  111.     procedure LF;
  112.     procedure ResetLineHeight;
  113.     procedure CRLF;
  114.     procedure GotoHeader;
  115.     procedure GotoFooter;
  116.     procedure GotoXY(NewXPos: double;
  117.                      NewYPos: double);
  118.     procedure Home;
  119.     procedure SetColumns(NewColumns: integer;
  120.                          Between: double);
  121.     procedure SetColumnWidth(Width: double;
  122.                              Between: double);
  123.     procedure SetTopOfPage;
  124.     function LinesLeft: integer;
  125.     function ColumnLinesLeft: integer;
  126.  
  127.   { Printing Methods }
  128.     procedure Print(Text: string);
  129.     procedure PrintCenter(Text: string;
  130.                           Pos: double);
  131.     procedure PrintFooter(Text: string;
  132.                           Justify: TPrintJustify);
  133.     procedure PrintHeader(Text: string;
  134.                           Justify: TPrintJustify);
  135.     procedure PrintLeft(Text: string;
  136.                         Pos: double);
  137.     procedure PrintLn(Text: string);
  138.     procedure PrintRight(Text: string;
  139.                          Pos: double);
  140.  
  141.   { Positioning Methods }
  142.     function PopPos: boolean;
  143.     function PushPos: boolean;
  144.     function RestorePos(Index: byte): boolean;
  145.     function SavePos(Index: byte): boolean;
  146.  
  147.   { Canvas Drawing Object Methods }
  148.     procedure SetBrush(NewColor: TColor;
  149.                        NewStyle: TBrushStyle;
  150.                        NewBitmap: TBitmap);
  151.     function CreateBrush(NewColor: TColor;
  152.                          NewStyle: TBrushStyle;
  153.                          NewBitmap: TBitmap): TBrush;
  154.     procedure SetFont(NewName: string;
  155.                       NewSize: integer);
  156.     function CreateFont(NewName: string;
  157.                         NewSize: integer): TFont;
  158.     procedure SetPen(NewColor: TColor;
  159.                      NewStyle: TPenStyle;
  160.                      NewWidth: integer;
  161.                      NewMode: TPenMode);
  162.     function CreatePen(NewColor: TColor;
  163.                        NewStyle: TPenStyle;
  164.                        NewWidth: integer;
  165.                        NewMode: TPenMode): TPen;
  166.  
  167.   { Tab Methods }
  168.     procedure SetTab(NewPos: double;
  169.                      NewJustify: TPrintJustify;
  170.                      NewWidth: double;
  171.                      NewMargin: double;
  172.                      NewLines: byte;
  173.                      NewShade: byte);
  174.     procedure ClearTabs;
  175.     procedure ResetTabs;
  176.     procedure Tab(LeftWidth: integer;
  177.                   RightWidth: integer;
  178.                   TopWidth: integer;
  179.                   BottomWidth: integer;
  180.                   ShadeOverride: integer);
  181.  
  182.   { GDI Wrapper Functions }
  183.     function CreatePoint(X,Y: double): TPoint;
  184.     function CreateRect(X1,Y1,X2,Y2: double): TRect;
  185.     procedure Arc(X1,Y1,X2,Y2,X3,Y3,X4,Y4: double);
  186.     procedure BrushCopy(const Dest: TRect;
  187.                               Bitmap: TBitmap;
  188.                         const Source: TRect;
  189.                               Color: TColor);
  190.     procedure Chord(X1,Y1,X2,Y2,X3,Y3,X4,Y4: double);
  191.     procedure CopyRect(const Dest: TRect;
  192.                              Canvas: TCanvas;
  193.                        const Source: TRect);
  194.     procedure Draw(X,Y: double;
  195.                    Graphic: TGraphic);
  196.     procedure DrawFocusRect(const Rect: TRect);
  197.     procedure Ellipse(X1,Y1,X2,Y2: double);
  198.     procedure FillRect(const Rect: TRect);
  199.     procedure FloodFill(X,Y: double;
  200.                         Color: TColor;
  201.                         FillStyle: TFillStyle);
  202.     procedure FrameRect(const Rect: TRect);
  203.     procedure LineTo(X,Y: double);
  204.     procedure MoveTo(X,Y: double);
  205.     procedure Pie(X1,Y1,X2,Y2,X3,Y3,X4,Y4: double);
  206.     procedure Polygon(const Points: array of TPoint);
  207.     procedure Polyline(const Points: array of TPoint);
  208.     procedure PrintBitmap(X,Y: double;
  209.                           ScaleX,ScaleY: double;
  210.                           Bitmap: TBitmap);
  211.     procedure PrintBitmapRect(X1,Y1,X2,Y2: double;
  212.                               Bitmap: TBitmap);
  213.     procedure Rectangle(X1,Y1,X2,Y2: double);
  214.     procedure RoundRect(X1,Y1,X2,Y2,X3,Y3: double);
  215.     procedure StretchDraw(const Rect: TRect;
  216.                                 Graphic: TGraphic);
  217.     procedure TextRect(      Rect: TRect;
  218.                              X,Y: double;
  219.                        const Text: string);
  220.  
  221.   { Public properties }
  222.     property Canvas: TCanvas;
  223.     property CurrentPage: integer;
  224.     property PageInvalid: boolean;
  225.     property XDPI: integer;
  226.     property YDPI: integer;
  227.     property LineNum: integer;
  228.     property ColumnNum: integer;
  229.     property LeftWaste: double;
  230.     property RightWaste: double;
  231.     property TopWaste: double;
  232.     property BottomWaste: double;
  233.     property Columns: integer;
  234.     property XPos: double;
  235.     property YPos: double;
  236.     property PageHeight: double;
  237.     property PageWidth: double;
  238.     property Bold: boolean;
  239.     property Underline: boolean;
  240.     property Italic: boolean;
  241.     property Strikeout: boolean;
  242.     property PrinterIndex: integer;
  243.     property DeviceName: string;
  244.     property DriverName: string;
  245.     property Port: string;
  246.     property Aborted: boolean;
  247.     property Printing: boolean;
  248.     property OriginX: double;
  249.     property OriginY: double;
  250.     property DevMode: PDevMode;
  251.     property BKColor: TColor;
  252.  
  253.   published
  254.  
  255.   { Published properties }
  256.     property FirstPage: integer;
  257.     property LastPage: integer;
  258.     property StatusLabel: TLabel;
  259.     property StatusFormat: string;
  260.     property StatusText: TStrings;
  261.     property LineHeightMethod: TLineHeightMethod;
  262.     property LinesPerInch: integer;
  263.     property Units: TPrintUnits;
  264.     property UnitsFactor: double;
  265.     property MarginLeft: double;
  266.     property MarginRight: double;
  267.     property MarginTop: double;
  268.     property MarginBottom: double;
  269.     property TabShade: integer;
  270.     property Title: string;
  271.     property TextBKMode: TBKMode;
  272.     property Destination: TDestination;
  273.     property FileName: string;
  274.     property PaintBox: TPaintBox;
  275.     property Copies: integer;
  276.     property Orientation: TPrinterOrientation;
  277.  
  278.   { Published events }
  279.     property OnPrint: TNotifyEvent;
  280.     property OnPrintPage: TPrintPageEvent;
  281.     property OnBeforePrint: TNotifyEvent;
  282.     property OnAfterPrint: TNotifyEvent;
  283.   end;
  284.  
  285.   procedure Register;
  286.  
  287. implementation
  288. end. { RPrinter }
  289.  
  290.